// src/utils/axios.ts
import axios from 'axios';

// 基础URL
const baseURL = 'http://localhost:3000'

// 创建axios实例
const instance = axios.create({
    baseURL,
    timeout:10000
})

// 请求拦截器
instance.interceptors.request.use(config => {
    const token = localStorage.getItem('token')
    if(token){
        config.headers.Authorization = `Bearer ${token}`
    }
    return config
}, err =>{
    return Promise.reject(err)
})

// 响应拦截器
instance.interceptors.response.use(response => {
    // const {data} = response
    return response
}, err => {
    // alert('请求出错,请稍后重试')
    return Promise.reject(err)
})
export default instance